package top.minuy.structure.graph.cc.bfs;

import top.minuy.res.graph.GraphRes;
import top.minuy.structure.graph.representations.table.Graph;

import java.util.ArrayList;

/**
 * 测试联通分量，广度优先遍历
 *
 * @author Minuy
 * @time 10:39
 * @date 2021/11/20
 */
public class Test {
    public static void main(String[] args) {
        System.out.println("先序遍历求联通分量：");
        Graph graph = new Graph(GraphRes.G_DFS_1);

        CC cc = new CC(graph);
        System.out.println("广度优先遍历联通分量：" + cc.count());
        System.out.println("联通：" + cc.isConnected(1, 6));
        System.out.println("联通：" + cc.isConnected(5, 2));
        System.out.println("联通：" + cc.isConnected(7, 6));
        ArrayList<Integer>[] comp = cc.components();
        for (int i = 0; i < comp.length; i++) {
            System.out.print(i + " : ");
            for (Integer v : comp[i]) {
                System.out.print(v + " ");
            }
            System.out.println();
        }
    }
}
